Imports System.Diagnostics.Process
Imports System.Threading
Public Class R_Summary_Report
    Dim WithEvents SBO_Application As SAPbouiCOM.Application
    Dim Ocompany As SAPbobsCOM.Company
    Sub New(ByVal ocompany1 As SAPbobsCOM.Company, ByVal sbo_application1 As SAPbouiCOM.Application)
        SBO_Application = sbo_application1
        Ocompany = ocompany1
    End Sub
    Public Sub Bind_Common(ByVal oform As SAPbouiCOM.Form)
        Try
            Dim thisMonth As New DateTime(DateTime.Today.Year, DateTime.Today.Month, 1)
            Dim firstDayThisMonth As DateTime
            Dim lastDayThisMonth As DateTime
            Dim lastDayNextMonth As DateTime
            firstDayThisMonth = thisMonth.AddMonths(0)
            lastDayNextMonth = thisMonth.AddMonths(1)
            lastDayThisMonth = lastDayNextMonth.AddDays(-1)
            oform.DataSources.UserDataSources.Add("oedit3", SAPbouiCOM.BoDataType.dt_DATE)
            oform.DataSources.UserDataSources.Add("oedit4", SAPbouiCOM.BoDataType.dt_DATE)
            oEdit = oform.Items.Item("8").Specific
            oEdit.DataBind.SetBound(True, "", "oedit3")
            oEdit.String = Format(firstDayThisMonth.Date, "dd/MM/yy")
            oEdit = oform.Items.Item("10").Specific
            oEdit.DataBind.SetBound(True, "", "oedit4")
            oEdit.String = Format(lastDayThisMonth.Date, "dd/MM/yy")

        Catch ex As Exception
            SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
        End Try

    End Sub
    Public Sub Bind_Training(ByVal oform As SAPbouiCOM.Form)
        Try

            oform.DataSources.UserDataSources.Add("oedit3", SAPbouiCOM.BoDataType.dt_SHORT_TEXT)
            oCombo = oform.Items.Item("5").Specific
            oCombo.DataBind.SetBound(True, "", "oedit3")
            Dim i As Integer = 0
            Dim Yr As Integer = DateTime.Now.Year
            For i = 2012 To Yr
                oCombo.ValidValues.Add(i.ToString, i.ToString)
            Next
            oCombo.Select(Now.Year.ToString, SAPbouiCOM.BoSearchKey.psk_ByValue)
        Catch ex As Exception
            SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
        End Try

    End Sub


    Private Sub SBO_Application_ItemEvent(ByVal FormUID As String, ByRef pVal As SAPbouiCOM.ItemEvent, ByRef BubbleEvent As Boolean) Handles SBO_Application.ItemEvent
        Try


            If pVal.FormUID = "Attendance_Summary_Report" And pVal.ItemUID = "Print" And pVal.Before_Action = True And pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED Then
                Dim trd As Threading.Thread
                trd = New Threading.Thread(AddressOf Attendance_Summary_Report)
                trd.IsBackground = True
                trd.SetApartmentState(ApartmentState.STA)
                trd.Start()
            End If

            '------------
            If pVal.FormUID = "Boarding_Summary_Report" And pVal.ItemUID = "Print" And pVal.Before_Action = True And pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED Then
                Dim trd As Threading.Thread
                trd = New Threading.Thread(AddressOf Boarding_Summary_Report)
                trd.IsBackground = True
                trd.SetApartmentState(ApartmentState.STA)
                trd.Start()
            End If

            '------------
            If pVal.FormUID = "Activities_Summary_Report" And pVal.ItemUID = "Print" And pVal.Before_Action = True And pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED Then
                Dim trd As Threading.Thread
                trd = New Threading.Thread(AddressOf Activities_Summary_Report)
                trd.IsBackground = True
                trd.SetApartmentState(ApartmentState.STA)
                trd.Start()
            End If

            '-----

            '------------
            If pVal.FormUID = "Training_Summary_Report" And pVal.ItemUID = "Print" And pVal.Before_Action = True And pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED Then
                Dim trd As Threading.Thread
                trd = New Threading.Thread(AddressOf Training_Summary_Report)
                trd.IsBackground = True
                trd.SetApartmentState(ApartmentState.STA)
                trd.Start()
            End If
        Catch ex As Exception

        End Try
    End Sub

    Public Sub Attendance_Summary_Report()
        oForm = SBO_Application.Forms.Item("Attendance_Summary_Report")
        Dim FDt As String = ""
        Dim TDt As String = ""
        oEdit = oForm.Items.Item("8").Specific
        If oEdit.String = "" Then
            FDt = "20000101"
        Else
            FDt = oEdit.Value
        End If
        oEdit = oForm.Items.Item("10").Specific
        If oEdit.String = "" Then
            TDt = Format(Now.Date, "yyyyMMdd")
        Else
            TDt = oEdit.Value
        End If
        Dim Sqlstr As String = ""
        Try
            SBO_Application.StatusBar.SetText("Retrieving Data", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success)
            Sqlstr = "select distinct T1.U_AI_Date,(SELECT count(T0.[U_AI_PetCode]) FROM [dbo].[@AI_ATTENDANCE]  T0 left join [dbo].[@AI_PETMASTER]  T2 on T0.[U_AI_PetCode] = T2.[U_PetCode] WHERE T2.[U_AI_Size] ='Small' AND T0.U_AI_Date=t1.U_AI_Date and T0.U_AI_NewDog='Y' GROUP BY T0.[U_AI_Date])as 'SmallNewDog',(SELECT count(T0.[U_AI_PetCode]) FROM [dbo].[@AI_ATTENDANCE]  T0 left join [dbo].[@AI_PETMASTER]  T2 on T0.[U_AI_PetCode] = T2.[U_PetCode] WHERE T2.[U_AI_Size] ='Small' AND T0.U_AI_Date=t1.U_AI_Date and T0.U_AI_NewDog='N' GROUP BY T0.[U_AI_Date])as 'SmallReg',(SELECT count(T0.[U_AI_PetCode]) FROM [dbo].[@AI_ATTENDANCE]  T0 left join [dbo].[@AI_PETMASTER]  T2 on T0.[U_AI_PetCode] = T2.[U_PetCode] WHERE T2.[U_AI_Size] ='Medium' AND T0.U_AI_Date=t1.U_AI_Date and T0.U_AI_NewDog='Y' GROUP BY T0.[U_AI_Date]) as 'MediumNewDog',(SELECT count(T0.[U_AI_PetCode]) FROM [dbo].[@AI_ATTENDANCE]  T0 left join [dbo].[@AI_PETMASTER]  T2 on T0.[U_AI_PetCode] = T2.[U_PetCode] WHERE T2.[U_AI_Size] ='Medium' AND T0.U_AI_Date=t1.U_AI_Date and T0.U_AI_NewDog='N' GROUP BY T0.[U_AI_Date]) as 'MediumReg',(SELECT count(T0.[U_AI_PetCode]) FROM [dbo].[@AI_ATTENDANCE]  T0 left join [dbo].[@AI_PETMASTER]  T2 on T0.[U_AI_PetCode] = T2.[U_PetCode] WHERE T2.[U_AI_Size] ='Large' AND T0.U_AI_Date=t1.U_AI_Date and T0.U_AI_NewDog='Y' GROUP BY T0.[U_AI_Date]) as 'LargeNewDog',(SELECT count(T0.[U_AI_PetCode]) FROM [dbo].[@AI_ATTENDANCE]  T0 left join [dbo].[@AI_PETMASTER]  T2 on T0.[U_AI_PetCode] = T2.[U_PetCode] WHERE T2.[U_AI_Size] ='Large' AND T0.U_AI_Date=t1.U_AI_Date and T0.U_AI_NewDog='N' GROUP BY T0.[U_AI_Date]) as 'LargeReg' ,(SELECT count(T0.[U_AI_PetCode]) FROM [dbo].[@AI_ATTENDANCE]  T0  WHERE  T0.U_AI_Date=t1.U_AI_Date GROUP BY T0.[U_AI_Date]) as 'Total' from [@AI_attendance] T1 where T1.U_AI_Date between '" & FDt & "' and '" & TDt & "'"
            Dim frm As MY_Report
            frm = New MY_Report
            frm.Attendance_Summary_Report(Sqlstr, Ocompany)
            frm.Text = "Attendance Summary Report"
            frm.TopMost = True
            frm.Activate()
            frm.ShowDialog()
        Catch ex As Exception
        End Try



    End Sub
    Public Sub Boarding_Summary_Report()
        oForm = SBO_Application.Forms.Item("Boarding_Summary_Report")
        Dim FDt As String = ""
        Dim TDt As String = ""
        oEdit = oForm.Items.Item("8").Specific
        If oEdit.String = "" Then
            FDt = "20000101"
        Else
            FDt = oEdit.Value
        End If
        oEdit = oForm.Items.Item("10").Specific
        If oEdit.String = "" Then
            TDt = Format(Now.Date, "yyyyMMdd")
        Else
            TDt = oEdit.Value
        End If
        Dim Sqlstr As String = ""
        Try
            SBO_Application.StatusBar.SetText("Retrieving Data", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success)
            Sqlstr = "select distinct T1.U_AI_ChkDt,(select count(T0.U_AI_PetCode) from [@AI_NIGHTSHIFT] T0 left join [dbo].[@AI_PETMASTER]  T2 on T0.[U_AI_PetCode] = T2.[U_PetCode] WHERE T2.[U_AI_Size] ='Small' AND T0.U_AI_ChkDt=t1.U_AI_ChkDt  GROUP BY T0.U_AI_ChkDt) as 'Small', " & _
"(select count(T0.U_AI_PetCode) from [@AI_NIGHTSHIFT] T0 left join [dbo].[@AI_PETMASTER]  T2 on T0.[U_AI_PetCode] = T2.[U_PetCode] WHERE T2.[U_AI_Size] ='Medium' AND T0.U_AI_ChkDt=t1.U_AI_ChkDt  GROUP BY T0.U_AI_ChkDt) as 'Medium' ," & _
"(select count(T0.U_AI_PetCode) from [@AI_NIGHTSHIFT] T0 left join [dbo].[@AI_PETMASTER]  T2 on T0.[U_AI_PetCode] = T2.[U_PetCode] WHERE T2.[U_AI_Size] ='Large' AND T0.U_AI_ChkDt=t1.U_AI_ChkDt  GROUP BY T0.U_AI_ChkDt) as 'Large' " & _
"from [@AI_NIGHTSHIFT] T1 where T1.U_AI_ChkDt between '" & FDt & "' and '" & TDt & "' "

            Dim frm As MY_Report
            frm = New MY_Report
            frm.Boarding_Summary_Report(Sqlstr, Ocompany)
            frm.Text = "Boarding Summary Report"
            frm.TopMost = True
            frm.Activate()
            frm.ShowDialog()
        Catch ex As Exception
        End Try
    End Sub
    Public Sub Activities_Summary_Report()
        oForm = SBO_Application.Forms.Item("Activities_Summary_Report")
        Dim FDt As String = ""
        Dim TDt As String = ""
        oEdit = oForm.Items.Item("8").Specific
        If oEdit.String = "" Then
            FDt = "20000101"
        Else
            FDt = oEdit.Value
        End If
        oEdit = oForm.Items.Item("10").Specific
        If oEdit.String = "" Then
            TDt = Format(Now.Date, "yyyyMMdd")
        Else
            TDt = oEdit.Value
        End If
        Dim Sqlstr As String = ""
        Try
            SBO_Application.StatusBar.SetText("Retrieving Data", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success)
            Sqlstr = "select distinct  T0.U_AI_Date,(select COUNT(T1.U_AI_PetCode) from [@AI_ACTIVITY] T1 where T1.U_AI_ProgCode='1stTick' and T1.U_AI_Date=T0.U_AI_Date Group by T1.U_AI_Date) As 'FirstTick' ," & _
"(select COUNT(T1.U_AI_PetCode) from [@AI_ACTIVITY] T1 where T1.U_AI_ProgCode='Walk' and T1.U_AI_Date=T0.U_AI_Date Group by T1.U_AI_Date) As 'ShortWalk' ," & _
"(select COUNT(T1.U_AI_PetCode) from [@AI_ACTIVITY] T1 where T1.U_AI_ProgCode='Walk1' and T1.U_AI_Date=T0.U_AI_Date Group by T1.U_AI_Date) As 'LongWalk' ," & _
"(select COUNT(T1.U_AI_PetCode) from [@AI_ACTIVITY] T1 where T1.U_AI_ProgCode='Swim' and T1.U_AI_Date=T0.U_AI_Date Group by T1.U_AI_Date) As 'Swimming' ," & _
"(select COUNT(T1.U_AI_PetCode) from [@AI_ACTIVITY] T1 where T1.U_AI_ProgCode='Walk2' and T1.U_AI_Date=T0.U_AI_Date Group by T1.U_AI_Date) As '2ndWalk' ," & _
"(select COUNT(T1.U_AI_PetCode) from [@AI_ACTIVITY] T1 where T1.U_AI_ProgCode='Walk3' and T1.U_AI_Date=T0.U_AI_Date Group by T1.U_AI_Date) As '3rdWalk' ," & _
"(select COUNT(T1.U_AI_PetCode) from [@AI_ACTIVITY] T1 where T1.U_AI_ProgCode='Bike Run' and T1.U_AI_Date=T0.U_AI_Date Group by T1.U_AI_Date) As 'BicycleRun' ," & _
"(select COUNT(T1.U_AI_PetCode) from [@AI_ACTIVITY] T1 where T1.U_AI_ProgCode='TAgility' and T1.U_AI_Date=T0.U_AI_Date Group by T1.U_AI_Date) As 'Agility' ," & _
"(select COUNT(T1.U_AI_PetCode) from [@AI_ACTIVITY] T1 where T1.U_AI_ProgCode='TObedien' and T1.U_AI_Date=T0.U_AI_Date Group by T1.U_AI_Date) As 'Obedience' ," & _
"(select COUNT(T1.U_AI_PetCode) from [@AI_ACTIVITY] T1 where T1.U_AI_ProgCode='QTick' and T1.U_AI_Date=T0.U_AI_Date Group by T1.U_AI_Date) As 'Quarantine' " & _
"from [@AI_ACTIVITY] T0 where T0.U_AI_Date between '" & FDt & "' and '" & TDt & "'"

            Dim frm As MY_Report
            frm = New MY_Report
            frm.Act_Summary_Report(Sqlstr, Ocompany)
            frm.Text = "Activities Summary Report"
            frm.TopMost = True
            frm.Activate()
            frm.ShowDialog()
        Catch ex As Exception
        End Try

    End Sub
    Public Sub Training_Summary_Report()
        oForm = SBO_Application.Forms.Item("Training_Summary_Report")
        Dim FDt As String = ""
        Dim TDt As String = ""
        oCombo = oForm.Items.Item("5").Specific
        Dim yr As String = ""
        Try
            yr = oCombo.Selected.Value
            FDt = yr & "-01-01"
            TDt = yr & "-12-31"
        Catch ex As Exception
            yr = Now.Year.ToString
            FDt = yr & "-01-01"
            TDt = yr & "-12-31"
        End Try

        Dim Sqlstr As String = ""
        Try
            SBO_Application.StatusBar.SetText("Retrieving Data", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success)
            '                    Sqlstr = "SELECT distinct YEAR = YEAR(T1.U_AI_Date), MONTH = MONTH(T1.U_AI_Date),MMM = UPPER(left(DATENAME(MONTH,T1.U_AI_Date),3)), " & _
            '"(select count(T0.U_AI_PetCode) FROM [@AI_ACTIVITY] T0  where T0.U_AI_Level='Basic'  and MONTH(T1.U_AI_Date)=MONTH(T0.U_AI_Date) and T0.U_AI_Date between '" & FDt & "' and '" & TDt & "'" & _
            '"GROUP BY YEAR(T0.U_AI_Date), MONTH(T0.U_AI_Date), DATENAME(MONTH,T0.U_AI_Date))as 'Basic',  " & _
            '"(select count(T0.U_AI_PetCode)    FROM [@AI_ACTIVITY] T0  where T0.U_AI_Level='Inter' and MONTH(T1.U_AI_Date)=MONTH(T0.U_AI_Date) and T0.U_AI_Date between '" & FDt & "' and '" & TDt & "'" & _
            '"GROUP BY YEAR(T0.U_AI_Date), MONTH(T0.U_AI_Date),DATENAME(MONTH,T0.U_AI_Date))as 'Inter'," & _
            '"(select count(T0.U_AI_PetCode) FROM [@AI_ACTIVITY] T0  where T0.U_AI_Level='Open' and MONTH(T1.U_AI_Date)=MONTH(T0.U_AI_Date) and T0.U_AI_Date between '" & FDt & "' and '" & TDt & "'" & _
            '"GROUP BY YEAR(T0.U_AI_Date),MONTH(T0.U_AI_Date),DATENAME(MONTH,T0.U_AI_Date))as 'Open' ," & _
            '         "(select count(T0.U_AI_PetCode) FROM [@AI_ACTIVITY] T0  where T0.U_AI_Level='Utility' and MONTH(T1.U_AI_Date)=MONTH(T0.U_AI_Date)and  T0.U_AI_Date between '" & FDt & "' and '" & TDt & "'" & _
            '"GROUP BY YEAR(T0.U_AI_Date),MONTH(T0.U_AI_Date), DATENAME(MONTH,T0.U_AI_Date))as 'Utility'  ," & _
            '         "(Select count(T0.U_AI_PetCode) FROM [@AI_ACTIVITY] T0  where T0.U_AI_Level='Contact' and MONTH(T1.U_AI_Date)=MONTH(T0.U_AI_Date)and  T0.U_AI_Date between '" & FDt & "' and '" & TDt & "'" & _
            '"GROUP BY YEAR(T0.U_AI_Date), MONTH(T0.U_AI_Date),DATENAME(MONTH,T0.U_AI_Date))as 'Contact'  ," & _
            '         "(select count(T0.U_AI_PetCode) FROM [@AI_ACTIVITY] T0  where T0.U_AI_Level='Tunnel' and MONTH(T1.U_AI_Date)=MONTH(T0.U_AI_Date)and  T0.U_AI_Date between '" & FDt & "' and '" & TDt & "'" & _
            '"GROUP BY YEAR(T0.U_AI_Date),MONTH(T0.U_AI_Date), DATENAME(MONTH,T0.U_AI_Date))as 'Tunnel'  ," & _
            '         "(select count(T0.U_AI_PetCode) FROM [@AI_ACTIVITY] T0  where T0.U_AI_Level='Jumps' and MONTH(T1.U_AI_Date)=MONTH(T0.U_AI_Date) and T0.U_AI_Date between '" & FDt & "' and '" & TDt & "'" & _
            '"GROUP BY YEAR(T0.U_AI_Date),MONTH(T0.U_AI_Date),DATENAME(MONTH,T0.U_AI_Date))as 'Jumps'  ," & _
            '         "(select count(T0.U_AI_PetCode) FROM [@AI_ACTIVITY] T0  where T0.U_AI_Level='Compet' and MONTH(T1.U_AI_Date)=MONTH(T0.U_AI_Date) and T0.U_AI_Date between '" & FDt & "' and '" & TDt & "'" & _
            '"GROUP BY YEAR(T0.U_AI_Date),MONTH(T0.U_AI_Date), DATENAME(MONTH,T0.U_AI_Date))as 'Compet' ," & _
            '         "(select count(T0.U_AI_PetCode) FROM [@AI_ACTIVITY] T0  where T0.U_AI_Level='Flyball' and MONTH(T1.U_AI_Date)=MONTH(T0.U_AI_Date) and T0.U_AI_Date between '" & FDt & "' and '" & TDt & "'" & _
            '"GROUP BY YEAR(T0.U_AI_Date), MONTH(T0.U_AI_Date),DATENAME(MONTH,T0.U_AI_Date))as 'Flyball'  ," & _
            '         "(select count(T0.U_AI_PetCode) FROM [@AI_ACTIVITY] T0  where T0.U_AI_Level='Frisbee' and MONTH(T1.U_AI_Date)=MONTH(T0.U_AI_Date) and T0.U_AI_Date between '" & FDt & "' and '" & TDt & "'" & _
            '" GROUP BY YEAR(T0.U_AI_Date),MONTH(T0.U_AI_Date), DATENAME(MONTH,T0.U_AI_Date))as 'Frisbee'" & _
            '" FROM [@AI_ACTIVITY] T1 where  T1.U_AI_Date between '" & FDt & "' and '" & TDt & "' ORDER BY YEAR,Month"
            Sqlstr = "SELECT distinct YEAR = YEAR(T1.U_AI_Date), MONTH = MONTH(T1.U_AI_Date),MMM = UPPER(left(DATENAME(MONTH,T1.U_AI_Date),3)), (select count(T0.U_AI_PetCode)     FROM [@AI_ACTIVITY] T0  where T0.U_AI_Level='Basic'  and MONTH(T1.U_AI_Date)=MONTH(T0.U_AI_Date) and T0.U_AI_Date between '" & FDt & "' and '" & TDt & "' GROUP BY YEAR(T0.U_AI_Date),          MONTH(T0.U_AI_Date),          DATENAME(MONTH,T0.U_AI_Date))as 'Basic',(select count(T0.U_AI_PetCode)    FROM [@AI_ACTIVITY] T0  where T0.U_AI_Level='Inter' and MONTH(T1.U_AI_Date)=MONTH(T0.U_AI_Date) and T0.U_AI_Date between '" & FDt & "' and '" & TDt & "' GROUP BY YEAR(T0.U_AI_Date), MONTH(T0.U_AI_Date), DATENAME(MONTH,T0.U_AI_Date))as 'Inter',(select count(T0.U_AI_PetCode)FROM [@AI_ACTIVITY] T0  where T0.U_AI_Level='Open' and MONTH(T1.U_AI_Date)=MONTH(T0.U_AI_Date) and T0.U_AI_Date between '" & FDt & "' and '" & TDt & "' GROUP BY YEAR(T0.U_AI_Date), MONTH(T0.U_AI_Date),DATENAME(MONTH,T0.U_AI_Date))as 'Open' ,(select count(T0.U_AI_PetCode) FROM [@AI_ACTIVITY] T0  where T0.U_AI_Level='Utility' and MONTH(T1.U_AI_Date)=MONTH(T0.U_AI_Date)and T1.U_AI_Date between '" & FDt & "' and '" & TDt & "' GROUP BY YEAR(T0.U_AI_Date), MONTH(T0.U_AI_Date), DATENAME(MONTH,T0.U_AI_Date))as 'Utility'  ,(Select count(T0.U_AI_PetCode) FROM [@AI_ACTIVITY] T0  where T0.U_AI_Level='Contact' and MONTH(T1.U_AI_Date)=MONTH(T0.U_AI_Date)and T1.U_AI_Date between '" & FDt & "' and '" & TDt & "' GROUP BY YEAR(T0.U_AI_Date), MONTH(T0.U_AI_Date), DATENAME(MONTH,T0.U_AI_Date))as 'Contact'  ,(select count(T0.U_AI_PetCode)    FROM [@AI_ACTIVITY] T0  where T0.U_AI_Level='Tunnel' and MONTH(T1.U_AI_Date)=MONTH(T0.U_AI_Date)and T1.U_AI_Date between '" & FDt & "' and '" & TDt & "' GROUP BY YEAR(T0.U_AI_Date), MONTH(T0.U_AI_Date), DATENAME(MONTH,T0.U_AI_Date))as 'Tunnel'  ,(select count(T0.U_AI_PetCode)FROM [@AI_ACTIVITY] T0  where T0.U_AI_Level='Jumps' and MONTH(T1.U_AI_Date)=MONTH(T0.U_AI_Date) and T0.U_AI_Date between '" & FDt & "' and '" & TDt & "' GROUP BY YEAR(T0.U_AI_Date), MONTH(T0.U_AI_Date), DATENAME(MONTH,T0.U_AI_Date))as 'Jumps'  ,(select count(T0.U_AI_PetCode)  FROM [@AI_ACTIVITY] T0  where T0.U_AI_Level='Compet' and MONTH(T1.U_AI_Date)=MONTH(T0.U_AI_Date) and T0.U_AI_Date between '" & FDt & "' and '" & TDt & "' GROUP BY YEAR(T0.U_AI_Date), MONTH(T0.U_AI_Date), DATENAME(MONTH,T0.U_AI_Date))as 'Compet' ,(select count(T0.U_AI_PetCode) FROM [@AI_ACTIVITY] T0  where T0.U_AI_Level='Flyball' and MONTH(T1.U_AI_Date)=MONTH(T0.U_AI_Date) and T0.U_AI_Date between '" & FDt & "' and '" & TDt & "' GROUP BY YEAR(T0.U_AI_Date), MONTH(T0.U_AI_Date), DATENAME(MONTH,T0.U_AI_Date))as 'Flyball'  ,(select count(T0.U_AI_PetCode) FROM [@AI_ACTIVITY] T0  where T0.U_AI_Level='Frisbee' and MONTH(T1.U_AI_Date)=MONTH(T0.U_AI_Date) and T0.U_AI_Date between '" & FDt & "' and '" & TDt & "' GROUP BY YEAR(T0.U_AI_Date),MONTH(T0.U_AI_Date), DATENAME(MONTH,T0.U_AI_Date))as 'Frisbee' FROM [@AI_ACTIVITY] T1 where  T1.U_AI_Date between '" & FDt & "' and '" & TDt & "' ORDER BY YEAR, MONTH "

            Dim frm As MY_Report
            frm = New MY_Report
            frm.Training_Summary_Report(Sqlstr, Ocompany)
            frm.Text = "Training Summary Report"
            frm.TopMost = True
            frm.Activate()
            frm.ShowDialog()
        Catch ex As Exception
        End Try

    End Sub
End Class
